package com.aaa.controller;

import com.aaa.entity.Book;
import com.aaa.entity.ResultMsg;
import com.aaa.service.BookServiceDao;
import com.aaa.util.AuthenticationUtils;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("book")
public class BookController {
    @Resource
    BookServiceDao bookServiceDao;
    @Resource
    AuthenticationUtils authenticationUtils;

    @RequestMapping("find")
    public ResultMsg find(String bName,String type) {
        return ResultMsg.success( bookServiceDao.findBook(bName,type));
    }
    @RequestMapping("saveorupdate")
    public ResultMsg add(Book book){
        return ResultMsg.success(bookServiceDao.saveOrUpdate(book));
    }
    @RequestMapping("getAuthentication")
    public ResultMsg getAuthentication(Authentication authentication) {
        return ResultMsg.success(authenticationUtils.getAdditionalInformation(authentication));
    }
}
